package com.ds.shopping_admin_service.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ds.shopping_admin_service.mapper.PermissionMapper;
import com.ds.shopping_common.pojo.Permission;
import com.ds.shopping_common.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 编写权限服务实现类
 */
@DubboService
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    //新增权限
    @Override
    public int findAdd(Permission permission) {
        return permissionMapper.insert(permission);
    }

    //修改权限
    @Override
    public int update(Permission permission) {
        return permissionMapper.updateById(permission);
    }

    //删除权限
    @Override
    public void delete(Long pid) {
        //删除权限
        permissionMapper.deleteById(pid);
        //删除角色_权限表中的相关数据
        permissionMapper.deletePermissionAllRole(pid);
    }

    //通过id查询权限
    @Override
    public Permission findById(Long pid) {
        return permissionMapper.selectById(pid);
    }

    //分页查询权限
    @Override
    public Page<Permission> search(int page, int size) {
      return  permissionMapper.selectPage(new Page(page,size),null);

    }

    //查询所有权限
    @Override
    public List<Permission> findAll() {

        return permissionMapper.selectList(null);
    }
}
